package com.accp.jboa.action;

import com.accp.jboa.biz.Employeebiz;
import com.accp.jboa.biz.Leavebiz;
import com.accp.jboa.pojo.Leave;
import com.accp.jboa.vo.EmployeeAndDepartmentAndLeaveAndStatus;
import com.accp.jboa.vo.Leaves;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/leave")
public class LeaveAction {

    @Autowired(required = false)
    private Leavebiz leavebiz;

    @RequestMapping(value = "/querybyid/{id}/{page}/{size}/{startTime}/{endTime}",method = RequestMethod.GET)
    public PageInfo<Leaves> querybyid(@PathVariable Integer id, @PathVariable Integer page, @PathVariable Integer size, @PathVariable String startTime, @PathVariable String endTime){
        System.out.println(id+" "+page+" "+size+" "+startTime+" "+endTime);
        return leavebiz.querybyid(id,page,size,startTime,endTime);
    }

    @PostMapping("/insert")
    public Map<String,String> insertLeave(@RequestBody Leave leave){
        int i = leavebiz.insertLeave(leave);
        if(i>0){
            Map<String,String> map = new HashMap<>();
//            map.put("checkid",i+"");
            map.put("code","200");
            map.put("msg","请假成功");
            return map;
        }else {
            Map<String,String> map = new HashMap<>();
            map.put("code","400");
            map.put("msg","请假失败");
            return map;
        }
    }

    @GetMapping("queryid/{id}")
    public Leave queryid(@PathVariable Integer id){
        return leavebiz.queryid(id);
    }

    @GetMapping("select/{id}")
    public EmployeeAndDepartmentAndLeaveAndStatus select(@PathVariable Integer id){
        return leavebiz.select(id);
    }
}
